function jumpPage(pageNo) {
	$("#pageNo").val(pageNo);
	$("#mainForm").submit();
}
function directPage(totalPages) {
	var pageNo = $('#pageIndex_input').val()
	if (isNaN(pageNo)) {
		alert("请输入数字")
		$('#pageIndex_input').val("");
		return false;
	} else if (pageNo - totalPages > 0) {
		pageNo = totalPages;
	}
	jumpPage(pageNo);
}
$(document).ready(function() {
	if ($("#mainForm")[0]) {
		$("#mainForm  table tr:nth-child(even)").addClass("odd");
		var orderByStr = $("#orderBy").val();
		var orderStr = $("#order").val();
		$('#pageIndex_input').bind("keypress", function() {
			if (event.keyCode == 13) {
				$('#pageIndex_button').click();
			}
		})
		if (orderByStr) {
			var orderByArray = orderByStr.split(",");
			var orderArray = orderStr.split(",");
			for ( var index = 0; index < orderByArray.length; index++) {
				var orderBy = orderByArray[index];
				var order = orderArray[index];
				if (order == "desc") {
					$("a[id='" + orderBy + "']").addClass("desc");
				} else if (order == "asc") {
					$("a[id='" + orderBy + "']").addClass("asc");
				}
			}
		}
	}
	
	 $(".uploadForm").Validform({
	        showAllError:false,
	        tiptype:function(msg,o,cssctl){
	            if(!o.obj.is("form")){
	                var objtip=o.obj.siblings(".Validform_checktip");
	                cssctl(objtip,o.type);
	                objtip.text(msg);
	            }
	        }
	    });
	
});

function delFile(id){
	 $('#confirmationModal').modal('show').on('shown.bs.modal',function(e){
         $("#delButton").attr('href',appConfig.contPath+'/attachment/attachment!deletePage.action?id='+id);
     })
}

function sort(orderBy, defaultOrder) {
	if (!orderBy || !defaultOrder) { // 判断非空,为空则返回为空
		return;
	}
	// $("#orderBy").val(); page.orderBy 'createDate,title' page.order
	// 'desc,asc'
	var orderByStr = $("#orderBy").val();
	var orderStr = $("#order").val();
	if (!orderByStr) { // 取不到值
		$("#orderBy").val(orderBy);
		$("#order").val(defaultOrder);
		$("#mainForm").submit();
		return;
	}
	var orderByArray = orderByStr.split(",");
	var orderArray = orderStr.split(",");
	var index = $.inArray(orderBy, orderByArray)
	/**
	 * 找到
	 */
	if (index != -1) {
		if (orderArray[index] == "desc") {
			defaultOrder = "asc";
		} else if (orderArray[index] == "asc") {
			defaultOrder = "desc";
		}
		orderByArray.splice(index,1);
		orderArray.splice(index,1);
		orderByStr = orderByArray.join(",");
		orderStr = orderArray.join(",");
	} 
	    //  添加到第一排序
		orderByStr =  orderBy+ "," + orderByStr ;
		orderStr =  defaultOrder+ "," + orderStr ;
	$("#orderBy").val(orderByStr);
	$("#order").val(orderStr);
	$("#mainForm").submit();
}

function search() {
	$("#order").val("");
	$("#orderBy").val("");
	$("#pageNo").val("1");
	$("#mainForm").submit();
}

//判断显示和隐藏返回按钮
function back(id){
	if(window.opener){
		$("#"+id).hide();
	}
}